package com.support.messagebus

import android.util.ArrayMap
import androidx.lifecycle.MutableLiveData

object LiveDataBus {

    private val liveDataPool = ArrayMap<String, MutableLiveData<Any>>()

    //注册
    fun <T> of(key: String): MutableLiveData<T> {
        if (!liveDataPool.containsKey(key)) {
            liveDataPool[key] = MutableLiveData()
        }
        return liveDataPool[key] as MutableLiveData<T>
    }

    //取消注册
    fun off(key: String) {
        if (liveDataPool.containsKey(key)) {
            liveDataPool.remove(key)
        }
    }
}